from lib2to3.pgen2 import driver

from common.serviceWeb import ServiceWeb

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class LoginOperater():
    def login(self,chromeDriver,username,password):
        # 显式等待账号输入框出现
        el1 = WebDriverWait(chromeDriver, 10).until(
            EC.presence_of_element_located((By.ID, "username"))
        )
        el1.send_keys(username)

        # 显式等待密码输入框出现
        el2 = WebDriverWait(chromeDriver, 10).until(
            EC.presence_of_element_located((By.ID, "password"))
        )
        el2.send_keys(password)

        # 显式等待登录键可点击
        """el3 = WebDriverWait(chromeDriver, 3).until(
            EC.element_to_be_clickable((By.ID, "login_btn"))
        )"""
        el3=chromeDriver.find_element(By.ID,"login_btn")
        el3.click()

        return chromeDriver


